﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class admin_contact_modifycontact : System.Web.UI.Page
{

    private TextBox[] phoneTextBoxArray;
    private TextBox[] faxTextBoxArray;
    protected void Page_Load(object sender, EventArgs e)
    {
        admin_contact_contact acc = Context.Handler as admin_contact_contact;
        if (acc == null)
            return;
        phoneTextBoxArray = new TextBox[] {phoneTextBox1,phoneTextBox2,phoneTextBox3 };
        faxTextBoxArray = new TextBox[] {faxTextBox1,faxTextBox2,faxTextBox3};
        DB db = new DB();
        Contact contact = db.getContact(Convert.ToInt32(acc.ContactId));
        addressTextBox_cn.Text = contact.Address_cn;
        addressTextBox_en.Text = contact.Address_en;
        postcodeTextBox.Text = Convert.ToString(contact.PostCode);
        for (int i = 0; i < contact.PhoneNumber.Count; ++i)
        {
            phoneTextBoxArray[i].Text = contact.PhoneNumber[i];
        }
        for (int j = 0; j < contact.Fax.Count; ++j)
        {
            faxTextBoxArray[j].Text = contact.Fax[j];
        }

        emailTextBox.Text = contact.Email;
        idLabel.Text = Convert.ToString(contact.ContactId);

    }
    protected void saveButton_Click(object sender, EventArgs e)
    {
        Contact contact = new Contact();
        if (idLabel.Text != null && !idLabel.Text.Equals(""))
        {
            contact.ContactId = Convert.ToInt32(idLabel.Text);
        }
        contact.Address_cn = addressTextBox_cn.Text;
        contact.Address_en = addressTextBox_en.Text;
        contact.Email = emailTextBox.Text;

        contact.PhoneNumber = new List<string>();

        contact.PhoneNumber.Add(phoneTextBox1.Text);
        contact.PhoneNumber.Add(phoneTextBox2.Text);
        contact.PhoneNumber.Add(phoneTextBox3.Text);

        contact.Fax = new List<string>();
        contact.Fax.Add(faxTextBox1.Text);
        contact.Fax.Add(faxTextBox2.Text);
        contact.Fax.Add(faxTextBox3.Text);
        contact.PostCode = Convert.ToInt32(postcodeTextBox.Text);

        DB db = new DB();
        db.modifyContact(contact);
    }
}
